﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
   public class DBhelper
    {
        static SqlConnection con = new SqlConnection("server=.;database=Orangelala;uid=sa;pwd=123456");
        static SqlCommand cmd = null;
        public static void Open()
        {

            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }

        }
        public static void Close()
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
         
        }
    public static bool ex(string sql)
        {
            Open();
            cmd = new SqlCommand(sql, con);
            int count = cmd.ExecuteNonQuery();
            Close();
            return count > 0;

        }
        public static SqlDataReader DataReader(string sql)
        {
            Open();
            cmd = new SqlCommand(sql, con);
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
    }
}
